package com.pig4cloud.pig.demo.Mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pig4cloud.pig.demo.feign.Entity.Article;
import com.pig4cloud.pig.demo.feign.Entity.Comment;
import com.pig4cloud.pig.demo.feign.Entity.Conlike;
import com.pig4cloud.pig.demo.feign.Entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommentMapper extends BaseMapper<Comment> {
    @Select("SELECT * FROM comment where aid=#{id} limit #{currentPage},#{size}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "content",property = "content"),
            @Result(column = "published",property = "published"),
            @Result(
                    column = "uid",
                    property = "user",
                    javaType = User.class,
                    one = @One(
                            select = "com.pig4cloud.pig.demo.Mapper.UserMapper.findById"
                    )
            ),
            @Result(
                    column = "cid",
                    property = "conlike",
                    javaType = Conlike.class,
                    one = @One(
                            select = "com.pig4cloud.pig.demo.Mapper.ConlikeMapper.findById"
                    )
            ),
            @Result(
                    column = "aid",
                    property = "article",
                    javaType = Article.class,
                    one = @One(
                            select = "com.pig4cloud.pig.demo.Mapper.ArticleMapper.findById"
                    )
            )
    })
    public List<Comment> getCommentAndLike(
            @Param("id") Long id,
            @Param("currentPage") int currentPage,
            @Param("size") int size);
}
